﻿package com.jfdesgagne.jfdesgagne09.core.controller {
	import com.jfdesgagne.jfdesgagne09.core.view.FrameView;
	import com.jfdesgagne.jfdesgagne09.JFDesgagne09;
	import flash.events.MouseEvent;
	import flash.display.MovieClip;
	import flash.display.DisplayObject;
	import flash.events.Event;
	
	public class FrameController {
		
		private var _frameView:FrameView;
		private var _jfDesgagne:JFDesgagne09;
		
		public function FrameController(_jfDesgagne:JFDesgagne09) {
			this._jfDesgagne = _jfDesgagne;
			this._initView();
			this._initEvents();
		}
		private function _initView():void {
			this._frameView = new FrameView(this._jfDesgagne.configurationModel.configuration_file.configuration.contact.email.toUpperCase());
			this._jfDesgagne.addChild(this._frameView);
			this._frameView.init();
		}
		private function _initEvents():void {
			this._jfDesgagne.addToResize(this._frameView.resize, this);
			this._frameView.mainMenuItems_array[0].section = "showcase";
			this._frameView.mainMenuItems_array[1].section = "profile";
			this._frameView.mainMenuItems_array[2].section = "blog";
			this._frameView.mainMenuItems_array[3].section = "contact";
			
			for(var i:Number=0; i<this._frameView.mainMenuItems_array.length; i++) {
				this._frameView.mainMenuItems_array[i].addEventListener(MouseEvent.ROLL_OVER, this._mainMenuItemRollOverHandler);
				this._frameView.mainMenuItems_array[i].addEventListener(MouseEvent.ROLL_OUT, this._mainMenuItemRollOutHandler);
				this._frameView.mainMenuItems_array[i].addEventListener(MouseEvent.CLICK, this._mainMenuItemClickHandler);
			
			}
			
			for(i=0; i<this._frameView.bottomMenuItems_array.length; i++) {
				this._frameView.bottomMenuItems_array[i].addEventListener(MouseEvent.ROLL_OVER, this._bottomMenuItemRollOverHandler);
				this._frameView.bottomMenuItems_array[i].addEventListener(MouseEvent.ROLL_OUT, this._bottomMenuItemRollOutHandler);
			}
			this._frameView.bottomMenuItems_array[1].addEventListener(MouseEvent.CLICK, this._fullscreenClickHandler);
		}
		
		private function _mainMenuItemClickHandler(event:MouseEvent):void {
			this._jfDesgagne.changeSection(event.target.section);
		}
		
		private function _fullscreenClickHandler(event:MouseEvent):void {
			this._jfDesgagne.toggleFullscreen();
		}
		
		private function _mainMenuItemRollOverHandler(event:MouseEvent):void {
			this._frameView.mainMenuItemRollOver(event.target as MovieClip);
			this._jfDesgagne.tooltipView.show(event.target as DisplayObject, event.target.letter, event.target.tooltip);
		}
		
		private function _mainMenuItemRollOutHandler(event:MouseEvent):void {
			this._frameView.mainMenuItemRollOut(event.target as MovieClip);
			this._jfDesgagne.tooltipView.hide();
		}
		
		private function _bottomMenuItemRollOverHandler(event:MouseEvent):void {
			this._frameView.bottomMenuItemRollOver(event.target as MovieClip);
			this._jfDesgagne.tooltipView.show(event.target as DisplayObject, event.target.letter, event.target.tooltip);
		}
		
		private function _bottomMenuItemRollOutHandler(event:MouseEvent):void {
			this._frameView.bottomMenuItemRollOut(event.target as MovieClip);
			this._jfDesgagne.tooltipView.hide();
		}
		
	}
}